1. /* sdfsindv.cpp by K.Tsuru */
  2. // function ID 3208 DRADIX
  3. /****************************************************************
  4. SDouble class
  5. sin x for |x| < pi/4
  6. The divide method is used similar to that used in Exp(x).
  7. x is divided into the sum
  8. x = a(short number)+b(long but very small number)
  9. and the addition theorem
  10. sin(a+b) = cos(a)*sin(b) + sin(a)*cos(b)
  11. is used.Combining with SinRN (x/(R^N) method) it becomes slower.
  12. ****************************************************************/
  13. #ifndef SN_H
  14. #include "sn.h"
  15. #endif
  16. SDouble SinDiv(const SDouble& x){
  17. // seriesFig : The change of this value refering the number of effective figures
  18. //yields the same speed or slower.
  19. const uint seriesFig = 4u;
  20. if(x.RdxExp() < -(int)seriesFig) return SinSeries(x); // |x| << 1.0
  21. SDouble a, b(x), y;
  22. //It takes out upper 'seriesFig' figures.
  23. // x = a+b, sin(x) = sin(a+b) = cos(a)*sin(b) + sin(a)*cos(b)
  24. if(x.Sign() < 0) b.ChangeSign(); // b = |x|
  25. a = b.TakeOutFigures(seriesFig);
  26. b -= a;
  27. if( b.Sign(3208) ){
  28. //Comparing 'SinSeries' an enough precision can be obtained.
  29. RealSize C;
  30. C.SetEffFig(x.EffFig() -seriesFig); //It can reduce the number of effective figures.
  31. b = SinSeries(b);
  32. C.SetEffFig(0);
  33. C.SetEffFig(x.EffFig() + 2u, C.TEMP_EXTEND);
  34. a = CosSeries(a);
  35. y = a*b + Sqrt((ONE - a*a)*(ONE - b*b));
  36. C.SetEffFig(0);
  37. y.Reform(3208);
  38. } else y = SinSeries(a); // b = 0 for short x.
  39. if(x.Sign() < 0) y.ChangeSign();
  40. return y;
  41. }

sdfsindv.cpp : last modifiled at 2017/09/05 16:16:44(1,500 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).